package com.meisiabc.app.service;

import com.meisiabc.app.repository.db.entity.FreeAudition;
import com.meisiabc.app.repository.db.entity.Student;
import com.meisiabc.app.repository.db.manager.FreeAuditionManager;
import com.meisiabc.app.repository.db.manager.StudentManager;
import com.meisiabc.utils.UUIDUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Slf4j
@Service
public class FreeAuditionService {
    @Autowired
    private FreeAuditionManager freeAuditionManager;
    @Autowired
    private StudentManager studentManager;

    public void register(String recommenderMobile, String mobile, String enName, Integer age, LocalDateTime applyTime) {
        Student student = studentManager.selectByMobile(recommenderMobile);

        String recommenderId = null;
        String recommenderName = null;
        if (student != null) {
            recommenderId = student.getStudentId();
            recommenderName = student.getEnName();
        }

        FreeAudition freeAudition = FreeAudition.builder().orderId(UUIDUtils.getUUID()).phone(mobile).enName(enName).age(age).applyTime(applyTime).isdeleted(0).state("待跟进").submitStatus("未提交").recommendId(recommenderId).recommendName(recommenderName).build();
        freeAuditionManager.save(freeAudition);
    }
}
